package com.codejiwei.core.rdd

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark_RDD_WholeTextFiles {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[1]").setAppName("WholeTextFiles")
    val sc = new SparkContext(conf)

    //返回值的RDD[(String, String)]第一个数据为文件名绝对路径，第二个数据为文件的完整内容
    val rdd: RDD[(String, String)] = sc.wholeTextFiles("spark-core/src/main/resources/word.txt")

    rdd.map{
      case (file, context) => ("===" + file + "===", context)
    }.collect()
      .foreach(println)
//    rdd.collect().foreach(println)
    sc.stop()
  }
}
